package top.lileix.mybatis.generator.x;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.druid.pool.DruidDataSource;

import top.lileix.mybatis.generator.x.db.MetaBuilder;
import top.lileix.mybatis.generator.x.domain.Table;
import top.lileix.mybatis.generator.x.generator.DomainGenerator;
import top.lileix.mybatis.generator.x.generator.MapperGenerator;
import top.lileix.mybatis.generator.x.generator.MapperXmlGenerator;

/**
 * Hello world!
 *
 */
public class App {
    static final String USER = "root";
    static final String PASS = "root";
    static final String DB_URL = "jdbc:mysql://localhost:3306/kr";

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
	Class.forName("com.mysql.jdbc.Driver");
	System.out.println("链接数据库");
	Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
	System.out.println("链接数据库：" + conn.getCatalog() + "成功");
	DruidDataSource ds = new DruidDataSource();
	ds.setUrl(DB_URL);
	ds.setPassword(PASS);
	ds.setUsername(USER);
	List<String> prefix = new ArrayList<String>() {
	    {
		add("t_");
		add("sys_");
	    }
	};
	MetaBuilder builder = new MetaBuilder(ds, prefix);
	List<Table> ts = builder.getAllTable();
	// DomainGenerator domainGenerator = new DomainGenerator(
	// "top.lileix.mybatis.generator.x.domain",
	// "./src/main/java/top/lileix/mybatis/generator/x/domain/");
	// try {
	// for (Table table : ts) {
	// domainGenerator.generatorFile(table);
	// }
	// } catch (IOException e) {
	// e.printStackTrace();
	// }
	// MapperGenerator g = new
	// MapperGenerator("top.lileix.mybatis.generator.x.mapper", "",
	// "top.lileix.mybatis.generator.x.domain");
	// System.err.println(g.generatorStr(ts.get(0)));

	MapperXmlGenerator x = new MapperXmlGenerator("", "top.lileix.mybatis.generator.x.mapper",
		"top.lileix.mybatis.generator.x.domain");
	System.err.println(x.generatorStr(ts.get(0)));
    }
}
